//
// Created by Shao Wenhan on 2021/9/28.
//

#include "ConfigurableEventListener.h"
#include "MedianOfUnabatedArray.h"

class TestMedianOfUnabatedArray: public testing::Test{
public:
    MedianOfUnabatedArray<int> findAndUpdateMedian;
};

TEST_F(TestMedianOfUnabatedArray, FindMediumAfterInsertOneNum)
{
    findAndUpdateMedian.insert(5);
    ASSERT_FLOAT_EQ(5, findAndUpdateMedian.getMedian());
}

TEST_F(TestMedianOfUnabatedArray, FindMediumAfterInsertTwoNums)
{
    findAndUpdateMedian.insert(5);
    findAndUpdateMedian.insert(8);
    ASSERT_FLOAT_EQ(6.5, findAndUpdateMedian.getMedian());
}

TEST_F(TestMedianOfUnabatedArray, FindMediumAfterInsertThreeNums)
{
    findAndUpdateMedian.insert(5);
    findAndUpdateMedian.insert(8);
    findAndUpdateMedian.insert(-2);
    ASSERT_FLOAT_EQ(5, findAndUpdateMedian.getMedian());
}

TEST_F(TestMedianOfUnabatedArray, FindMediumAfterInitial)
{
    findAndUpdateMedian.insert(5);
    findAndUpdateMedian.insert(8);
    findAndUpdateMedian.insert(-2);

    findAndUpdateMedian.initial();
    findAndUpdateMedian.insert(9);

    ASSERT_FLOAT_EQ(9, findAndUpdateMedian.getMedian());
}

GTEST_API_ int main(int argc, char** argv) {
    testing::InitGoogleTest(&argc, argv);
    initialGTest();
    return RUN_ALL_TESTS();
}
